//
//  BQTabBar.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/22.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class BQTabBar: UITabBar {

    //定义一个闭包
    var colure:(()->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        
       
        
    }
    
    //点击事件
    func buttonClink(){
        
        
        colure?()
    }
    
    //重写layout方法
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w:CGFloat = self.frame.size.width * 0.2
        
        var index:CGFloat = 0
        
        for value in subviews{
            
            if value.isKind(of: NSClassFromString("UITabBarButton")!){
                
                value.frame.origin.x = index * w
                
                value.frame.size.width = w
                
                index += 1
                
                if(index == 2)
                {
                    index += 1
                }
            }
        }
        
        button.center.x = self.frame.size.width * 0.5
        
        button.center.y = self.frame.size.height * 0.5
    }
    
    //视图初始化方法
    private func setupUI(){
        
    
        addSubview(button)
        
        
    }
    //懒加载
    private lazy var button:UIButton = UIButton(target: self, action: #selector(buttonClink), imgName: "tabbar_compose_icon_add", backImg: "tabbar_compose_button",title:nil)
//    private lazy var button:UIButton = {
    
//        let button :UIButton = UIButton()
//        
//        button.addTarget( self, action: #selector(buttonClink), for: UIControlEvents.touchUpInside)
//        button.setImage(UIImage(named:"tabbar_compose_icon_add"), for: UIControlState.normal)
//        
//        button.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), for: UIControlState.highlighted)
//        button.setBackgroundImage(UIImage(named:"tabbar_compose_button"), for: UIControlState.normal)
//        
//        button.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), for: UIControlState.highlighted)
//        
//        button.sizeToFit()
//        
//        return button
//        
//    }()
}
